package org.darkforest.controller;

import java.util.List;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import org.darkforest.dao.mapper.ArticleMapper;
import org.darkforest.model.Article;
import org.darkforest.model.RestEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "article")
@Api(value = "article", description = "文章管理",produces= MediaType.APPLICATION_JSON_VALUE)
public class ArticleController {

    @Autowired
    private ArticleMapper articleMapper;

    @RequestMapping(value = "aboutUs",method = RequestMethod.GET)
    @ApiOperation(value = "关于我们", httpMethod = "GET",produces= MediaType.APPLICATION_JSON_VALUE)
    public RestEntity aboutUs(@RequestParam(required = false, defaultValue = "0") Integer sortId){
        try{

            Article article = new Article();
            // 关于我们 的文章分类=7
            article.setAcId(7);

            List<Article> aboutUsList = articleMapper.findArticleByCondition(article);

            // sortId == 0 ： 两条都取
            // sortId == 1 ： 取第一条
            if (sortId == 1) {
                aboutUsList.remove(1);
            }
            // sortId == 2 ： 取第二条
            if (sortId == 2) {
                aboutUsList.remove(0);
            }

            return RestEntity.success(aboutUsList);
        }catch (Exception e){
            return RestEntity.failed();
        }
    }
}
